#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = N * 7, mod = 998244353;
LL f[N], g[N];
int h[N], e[M], ne[M], idx;
int d[N];
int n, m;
int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void toupu_sort()
{
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!d[i])q.push(i);
	}
	while (q.size()) {
		int t = q.front();
		//cout << "  t==" << t << endl;
		q.pop();
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			g[j] = (g[j] + g[t]) % mod;
			f[j] = (f[j] + f[t] + g[t]) % mod;
			if (--d[j] == 0)q.push(j);
		}
	}
}
LL fun(LL a, LL b)
{
	LL ans = 1;
	while (b) {
		if (b & 1)ans = ans * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return ans;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		add(a, b);
		d[b]++;
	}
	for (int i = 1; i <= n; i++)g[i] = 1;
	toupu_sort();
	LL ans1 = 0, ans2 = 0;
	for (int i = 1; i <= n; i++) {
		ans1 = (ans1 + g[i]) % mod;
		ans2 = (ans2 + f[i]) % mod;
	}
	//cout << ans1 << " " << ans2 << endl;
	int d = gcd(ans1, ans2);
	ans1 /= d;
	ans2 /= d;
	//cout << ans2 << "/" << ans1 << endl;
	cout << (ans2 * fun(ans1, mod - 2)) % mod << endl;
	return 0;
}